<?php

declare(strict_types=1);

namespace So;

use Hyperf\Contract\ConfigInterface;

/**
 * 继承Hyperf Server进行重写
 * @author Saopig <1306222220@qq.com>
 */
class Server extends \Hyperf\HttpServer\Server
{
    /**
     * 加载So的全局中间件与Hyperf中间件合并
     * @param string $serverName
     */
    public function initCoreMiddleware(string $serverName): void
    {
        $config = $this->container->get(ConfigInterface::class);
        $middlewares = $config->get('middlewares',[]);
        foreach ($middlewares as $k => &$v){
            $v = array_merge($v,$config->get('so.middlewares.'.$k,[]));
        }
        $config->set('middlewares',$middlewares);
        parent::initCoreMiddleware($serverName); // TODO: Change the autogenerated stub
    }
}
